﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.Entity;
using LeadMaster.DAL;
using LeadMaster.Models;
using System.Data.SqlClient;


namespace LeadMaster.Helpers
{
    public class GenericRepository
    {
        private DunsmoreContext db = new DunsmoreContext();

        public virtual IEnumerable<Chasers> GetChasers(string query)
        {
            List<Chasers> chasers = db.Chasers.SqlQuery(query).ToList();
            return chasers;
        }

        public virtual List<NextRef> GetNextRef(string query)
        {
            List<NextRef> refs = db.NextRef.SqlQuery(query).ToList();
            return refs;
        }

        public virtual bool RefreshPO(string pid)
        {
          //db.RefreshPO.SqlQuery("exec dbo.RefreshPO @pid='" + pid + "', @resultset=0");
          string conxString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString();
          SqlConnection conn = new SqlConnection(conxString);
          SqlCommand cmd = new SqlCommand("dbo.RefreshPO");
          cmd.Connection = conn;
          cmd.Connection.Open();
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.Parameters.AddWithValue("@pid", pid);
          cmd.Parameters.AddWithValue("@resultset", 0);
          object returnVal = cmd.ExecuteScalar();
          //SqlDataReader rdr = cmd.ExecuteReader();
          cmd.Connection.Close();
          return true;
        }

        public virtual bool ResetLockout()
        {
          bool resultset = db.ResetLockout.SqlQuery("exec ResetLockout").FirstOrDefault().result;
          return resultset;
        }

        public virtual IEnumerable<QCOrder> GetQCOrder(string query)
        {
          List<QCOrder> qcorder = db.QCOrder.SqlQuery(query).ToList();
          return qcorder;
        }
    }
}